package com.jerkin.jcseg;

import org.lionsoul.jcseg.ISegment;
import org.lionsoul.jcseg.IWord;
import org.lionsoul.jcseg.dic.ADictionary;
import org.lionsoul.jcseg.dic.DictionaryFactory;
import org.lionsoul.jcseg.segmenter.SegmenterConfig;

import java.io.IOException;
import java.io.StringReader;

/**
 * @version V1.0
 * @ClassName: JcsegTest
 * @Description:
 * @author: huhongzhi
 * @date: 2021/1/25 11:01
 */
public class JcsegTest {

    public static void main(String[] args) throws IOException {
//        String strPath = System.getProperty("user.dir");
//        WordConfTools.set("dic.path", "classpath:dic.txt");
//        DictionaryFactory.reload();// 更改词典路径之后，重新加载词典
//        List<Word> words = WordSegmenter.segWithStopWords("蘑菇钉促销活动");
//        for (Word w : words) {
//            System.out.print(w + "_");
//        }

        SegmenterConfig segmenterConfig = new SegmenterConfig(Boolean.TRUE);
        segmenterConfig.setClearStopwords(Boolean.TRUE);    //设置不过滤停止词
        segmenterConfig.setAppendCJKSyn(false);      //设置关闭同义词追加
        segmenterConfig.setKeepUnregWords(false);    //设置去除不识别的词条
        segmenterConfig.setEnSecondSeg(false);       //关闭英文自动二次切分
//        segmenterConfig.load(new FileInputStream());
        ADictionary dic = DictionaryFactory.createSingletonDictionary(segmenterConfig);

        ISegment seg = ISegment.Type.fromIndex(ISegment.NLP_MODE).factory.create(segmenterConfig, dic);
        String value = "蘑菇钉促销活动";
        seg.reset(new StringReader(value));

//获取分词结果
        IWord word = null;
        while ( (word = seg.next()) != null ) {
            System.out.println(word.getValue());
        }

    }
}
